package utils

import (
	"fmt"
	"gopkg.in/ini.v1"
)

var (
	AppMode string
	HttpPort string
	JwtKey string
	Db string
	DbHost string
	DbPort string
	DbUser string
	DbPassword string
	DbName string
	DbCharset string
	AccessKey string
	SecretKey string
	Bucket string
	QiniuServer string
)

func init()  {
	file, err := ini.Load("config/config.ini")
	if err != nil {
		fmt.Println("配置文件读取错误" , err)
		return
	}
	LoadServer(file)
	LoadData(file)
	LoadQiNiu(file)
}

func LoadServer(file *ini.File)  {
	section := file.Section("server")
	AppMode = section.Key("AppMode").MustString("debug")
	HttpPort = section.Key("HttpPort").MustString(":3000")
	JwtKey = section.Key("JwtKey").MustString("")
}

func LoadData(file *ini.File)  {
	section := file.Section("database")
	Db = section.Key("Db").MustString("mysql")
	DbHost = section.Key("DbHost").MustString("localhost")
	DbPort = section.Key("DbPort").MustString("3306")
	DbUser = section.Key("DbUser").MustString("root")
	DbPassword = section.Key("DbPassword").MustString("zhangfq")
	DbName = section.Key("DbName").MustString("ginblog")
	DbCharset = section.Key("DbCharset").MustString("utf8")
}

func LoadQiNiu(file *ini.File) {
	section := file.Section("qiniu")
	AccessKey = section.Key("AccessKey").MustString("")
	SecretKey = section.Key("SecretKey").MustString("")
	Bucket = section.Key("Bucket").MustString("")
	QiniuServer = section.Key("QiniuServer").MustString("")
}